{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Project #2: Understanding root and equation systems\n",
    "\n",
    "\n",
    "- 姓名: 张可循\n",
    "- 专业：电子科学与技术\n",
    "- 学号: 20201050444\n",
    "- 邮箱: 1215775970@qq.com  (汪汪队背大锅)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"image.png\" width = \"500\" height = \"500\" alt=\"image\" align = center/>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. Root（方程求根）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.1 Fix point iteration（不动点迭代法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义迭代函数\n",
    "def CalXNew(XOld):\n",
    "    XNew = 5 / XOld / (1 + XOld) + XOld / (1 + XOld)\n",
    "    return XNew"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "XOld = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "CalXNew(XOld)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "iList = []\n",
    "XNewList = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "XNewList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 1.7099669239736828\n"
     ]
    }
   ],
   "source": [
    "# start iteration\n",
    "for i in range(100):\n",
    "    XNew = CalXNew(XOld)\n",
    "    XOld = XNew\n",
    "    iList.append(i)\n",
    "    XNewList.append(XNew)\n",
    "print(i, XNew)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "# iList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "# XNewList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Xnew')"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEGCAYAAAB/+QKOAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAA28UlEQVR4nO3deZxcdZ3v/9enTlXvnc7W2VdWBZTFGEFA0BEFFRnner3AyCxXRR28ozM+xquzOOP85udv7jjjb0ZBGVQGGLfrAgxX2UdkEVmSGCAQCCGQfemsnV6rq+pz/zjnVJ3aQoek0kn3+/l49CNV33Oq+ns6SX368/18v99j7o6IiEil1Fh3QEREjk4KECIiUpMChIiI1KQAISIiNSlAiIhITemx7sDhNH36dF+0aNFYd0NE5JixfPnyne7eXevYuAoQixYtYtmyZWPdDRGRY4aZra93TENMIiJS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mISUREalKAEBGRmhQgRESkJgUIERGpSQFCRERqUoAQEZGaFCBERKSm/wuhXfW0I33nzwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(iList, XNewList)\n",
    "plt.xlabel(\"iteration number\")\n",
    "plt.ylabel(\"Xnew\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.2 Newton method（牛顿法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(x):\n",
    "    return x**3 - 5 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "def fder(x):\n",
    "    return 3 * x**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [],
   "source": [
    "def calXnew(Xold):\n",
    "    return Xold - f(Xold) / fder(Xold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "Xold = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.333333333333333"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "calXnew(Xold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "iList = []\n",
    "XnewList = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "XnewList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 1.709975946676697\n"
     ]
    }
   ],
   "source": [
    "# start iteration\n",
    "for i in range(100):\n",
    "    Xnew = calXnew(Xold)\n",
    "    Xold = Xnew\n",
    "    iList.append(i)\n",
    "    XnewList.append(Xnew)\n",
    "print(i, Xnew)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [],
   "source": [
    "# iList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "# XnewList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Xnew')"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEGCAYAAABo25JHAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAYT0lEQVR4nO3dfZDdVX3H8ffnPixsgCRoVkQIBhUF6vDkqiiIKVoFq6LVqaKCUjXaMgqW+oRObetMR6sytVrEKBSxiGMhWNQqIIKUB4FNDElICIKIpgZZERICmOxmv/3jd+7m7s3dzc3Db292z+c1s7P34be/+z0T2M+ec37n/BQRmJlZvirdLsDMzLrLQWBmljkHgZlZ5hwEZmaZcxCYmWWu1u0CttecOXNi3rx53S7DzGxKWbx48e8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sbGf4vTMduyCfhRerwc2BgRQ5KWt/z8tRHxcPr8RanWYeAFwB2pg9LLlo3JNlNsRmi2FQeBTXUCPhARV495sRhqebzl+SuBl0TEE5JuAPbs4Nzj2dj0eDPj/7+0sc0xw4wdlm2uYygiGvu+jDR+PiJG0o1YGlr3holU7zci4uNt6vhjCjSzrXiOwKaax4B9mp5fDfx12n4bSc9NN2hpNQt4JIXAoRS38mwYavx8ixuBt6R5iD6KO4Jt366O7f0KOEpSRdJctvNuUsmfqbiHbS/FnapuptiI7M2Sngaj97h95i6o16Y59whsqlkGDEu6k+K+rl+kGDJZkiZsB2l/m8IfAe+XtIxih8afNb23EFgmaUlEvL3p9SspJlbvpPiL+yMR8WAKkp1xM3A/xdDPCmDJDpzjJoqdN58DfCsiBgAkfRK4RlKFYufKM4EHdrJem+a8+6iZWeY8NGRmljkHgZlZ5hwEZmaZcxCYmWXOQWBmljkHgZlZ5hwEZmaZ+3+HTJrQ6CV2cwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(iList, XnewList)\n",
    "plt.xlabel(\"iteration number\")\n",
    "plt.ylabel(\"Xnew\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.3 Bisection（二分法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.25\n",
      "1.375\n",
      "1.4375\n",
      "1.40625\n",
      "1.421875\n",
      "1.4140625\n",
      "1.41796875\n",
      "1.416015625\n",
      "1.4169921875\n",
      "1.41650390625\n",
      "1.416748046875\n",
      "1.4166259765625\n",
      "1.41668701171875\n",
      "1.416656494140625\n",
      "1.4166717529296875\n",
      "1.4166641235351562\n",
      "1.4166679382324219\n",
      "middle: 1.4166679382324219   left: 1.4166641235351562   right: 1.4166717529296875\n"
     ]
    }
   ],
   "source": [
    "def f(Xold):\n",
    "    return (Xold) ** 2 - 2\n",
    "\n",
    "left = 1                  #设置好左右极限\n",
    "right = 2\n",
    "middle = (left + right) / 2\n",
    "while True:\n",
    "    if f(middle) > 0:     #当中值处的函数值大于零时，将中值的x坐标赋值给右极限\n",
    "        right = middle\n",
    "        middle = (left + right) / 2\n",
    "        print(middle)\n",
    "        \n",
    "    if f(middle) == 0:    #错误报警\n",
    "        print(\"Error\")\n",
    "        print(middle)\n",
    "           \n",
    "    else:                 #当中值处的函数值小于零时，将中值的x坐标赋值给左极限\n",
    "        left = middle\n",
    "        middle = (left + right) / 2\n",
    "        print(middle)\n",
    "        \n",
    "    difference = abs(left - right)      #当左右极限的差值小于设定的diff值时即终止循环\n",
    "    if difference <0.00001:\n",
    "        break\n",
    "print(\"middle:\",middle,\"  left:\",left,\"  right:\",right)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.4 Secant（割线法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sec(x,y):\n",
    "    return x - (x**3 + x - 1) * (x - y)/(x**3+x - y ** 3- y + 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [],
   "source": [
    "array=np.zeros((50,4))\n",
    "i=0\n",
    "array[0,0]=0\n",
    "array[0,1]=100"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "index 50 is out of bounds for axis 0 with size 50",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_6060/3897584464.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m     \u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0msec\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m     \u001b[0md\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mabs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m     \u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m     \u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[0md\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mabs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexError\u001b[0m: index 50 is out of bounds for axis 0 with size 50"
     ]
    }
   ],
   "source": [
    "while True:\n",
    "    array[i,2]=sec(array[i,1],array[i,0])\n",
    "    d=abs(array[i,0]-array[i,1])\n",
    "    array[i+1,0]=array[i,1]\n",
    "    array[i+1,1]=array[i,2]\n",
    "    d=abs(array[i,0]-array[i,1])\n",
    "    if d<1e-5:\n",
    "        break\n",
    "    array[i,3]=i+1\n",
    "    i=i+1\n",
    "print(array[i,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Xnew')"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAEOCAYAAAB1g0unAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAV4klEQVR4nO3df7Bc5X3f8ffn3r3sxbEzhiAI5UdFHMUJdWtwVRtK0oJJWpIwhukMLa4dK4QZph0nwamTFCfjErf12J1knMRpkhnGdqypXVzGcQLjcVszwhS7cbCFweWHYNAQGwgykn8kdjyRQNK3f5xzdVc/7tVZ6d67K533a0azd8/uar+PJevD83zPOU+qCkmSupiZdAGSpBOHoSFJ6szQkCR1ZmhIkjozNCRJnQ0mXcBqOuOMM2r9+vWTLkOSTigPPPDA16tq3ZFeO6lDY/369WzdunXSZUjSCSXJV5d6zeUpSVJnhoYkqTNDQ5LUmaEhSerM0JAkdTax0EjyoSQ7kzwycuz0JHcnebJ9PG3ktXck2Z7kiST/fDJVS1K/TXKm8WHgqkOO3QJsqaoNwJb2OUkuBK4H/l77mT9IMrt2pUqSYIKhUVX3Ad885PA1wOb2583AtSPHP1ZVe6rqL4DtwGtXq7Ydf/23vO/TT/DUrr9Zra+QpBPStPU0zqqqHQDt45nt8XOAZ0be92x77DBJbkqyNcnWXbt2HVMRu76zh/ffs52ndn33mD4vSSeraQuNpeQIx464e1RV3VZVG6tq47p1R7wK/qjm55qVrz179x/T5yXpZDVtofF8krMB2sed7fFngfNG3ncu8Nx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ht9RXiSn6JZ75wFPlRV755sRasnye3A5TS3RX4euBX4U+AO4HzgaeC6qjq0WX7CS/KjwGeBh1lc1/41mr5GH8b/D2ianbM0/6F4R1X9xyTfRw/Gv6Bdnvrlqrq6L2NP8gM0swto2hH/varefTzj73VoSJLG0+flKUnSmAwNSVJnhoYkqTNDQ5LUmaEhSerM0JAmIMnlSSrJz066FmkchoYkqTOv05AmIMkMcArwYntfKOmEYGhIkjpzeUqaAHsaOlEZGpKkzgwNSVJnhoYkqTNDQ5LUmaEhSerM0JAkdWZoSJI6MzQkSZ0ZGpKkzryNiCSpM2cakqTODA1JUmeGhiSpM0NDktSZoSFJ6szQkCR1ZmhIkjozNCRJnRkakqTO/j/lgBAOdJpfrgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(array[:i,3],array[:i,1])\n",
    "plt.xlabel(\"i\",fontsize=18)\n",
    "plt.ylabel(\"Xnew\",fontsize=18)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.5 关于方程求根，不同的方法或者算法的优劣的思考\n",
    "    不动点迭代法：该方法很容易计算出其迭代方程。但是收敛速度比较慢。\n",
    "        牛顿法：该方法收敛速度很快，但是需要方程的导数。如果方程及其复杂或者难以求导则会比较尴尬。\n",
    "        二分法：该方法计算简单，且对f(x)的要求不高，只要连续且有解即可。但是其收敛速度也比较慢。\n",
    "        割线法：割线法的收敛性很稳定，但是需要预估两个起始值。\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Equation systems（线性方程组）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 Gauss elimination（高斯消元法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 要形成出一个上三角矩阵\n",
    "import numpy as np\n",
    "np.set_printoptions(3)                 #设置 保留小数点后3位小数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 4\n",
    "A = np.random.randn(n,n)               #rand为随机数,这里会创建一个随机的4x4矩阵\n",
    "b = np.random.randn(n,1)\n",
    "#附另一种定义矩阵的方法：\n",
    "#A = np.array([\n",
    "    #[1,2,3]\n",
    "    #[1,1,3]\n",
    "    #[2.1.4]\n",
    "#])\n",
    "#b = np.array([\n",
    "    #[2][5][4]\n",
    "#])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "A1 = A.copy()                          #如果这里用A1= A,则A1和A两个数组仍然是同一个地址，那么操作的时候就会对A进行操作，就影响源矩阵了。\n",
    "b1 = b[:,0].copy()\n",
    "for i in range (0 , n):\n",
    "    for j in range(i + 1, n):\n",
    "        C = - A[j , i] / A [i , i]\n",
    "        b1[j] = b[j] + C*b[i]\n",
    "        for k in range(i , n):\n",
    "            A1[j, k] = A[j , k] + C *A[i , k]                #如果报错了，则是随机出来的矩阵有问题，需重新运行。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.057, -0.958, -0.258, -1.737],\n",
       "       [ 0.   , -0.795,  0.409, -2.613],\n",
       "       [ 0.   ,  0.   , -5.393,  4.22 ],\n",
       "       [ 0.   ,  0.   ,  0.   , -0.583]])"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Define your problem here（定义你的线性方程组问题）\n",
    "- 用Markdown写出你要求解的方程组\n",
    "- 将该方程组转换成矩阵的形式，并用Markdown表示\n",
    "- 写出对应的矩阵A和向量b\n",
    "- 参考资料：https://zhuanlan.zhihu.com/p/269245898"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 求解方程组：\n",
    "$$\\begin{cases}\n",
    "    2x+3y+5z=10\\\\\n",
    "    3x+4y+6z=20\\\\\n",
    "    5x+6y+7z=45\\\\\n",
    "\\end{cases}\n",
    "$$\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "## 矩阵表示\n",
    "\n",
    "$$\\begin{bmatrix}\n",
    "    2&3&5\\\\\n",
    "    3&4&6\\\\\n",
    "    5&6&7\\\\\n",
    "\\end{bmatrix}$$           \n",
    "$$\\begin{bmatrix}\n",
    "    10\\\\\n",
    "     20\\\\\n",
    "    45\\\\\n",
    "\\end{bmatrix}$$\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "## 矩阵A\n",
    "\n",
    "$$\\begin{bmatrix}\n",
    "    2&3&5\\\\\n",
    "    3&4&6\\\\\n",
    "    5&6&7\\\\\n",
    "\\end{bmatrix}$$\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "## 向量b\n",
    "$$\\begin{bmatrix}\n",
    "    10\\\\\n",
    "     20\\\\\n",
    "    45\\\\\n",
    "\\end{bmatrix}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Convert your problem to python codes（转换成python代码）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [],
   "source": [
    "n = 3\n",
    "# A = np.random.randn(n, n)\n",
    "# b = np.random.randn(n,1)\n",
    "A = np.array([\n",
    "    [2, 3, 5],\n",
    "    [3, 4, 6],\n",
    "    [5, 6, 7]\n",
    "])\n",
    "b = np.array([\n",
    "    [10], [20], [45]\n",
    "])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: elimination（消元）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Old version"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "A1 = A.copy()\n",
    "b1 = b[:, 0].copy()\n",
    "for i in range(0, n+1):\n",
    "    for j in range(i + 1, n):\n",
    "        C = - A[j, i] / A[i, i]\n",
    "        b1[j] = b[j] + C * b[i]\n",
    "        for k in range(i, n):\n",
    "            A1[j, k] = A[j, k] + C * A[i, k]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2,  3,  5],\n",
       "       [ 0,  0, -1],\n",
       "       [ 0,  0, -2]])"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([10,  5, 15])"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### new verison"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\12157\\AppData\\Local\\Temp/ipykernel_6060/1013505609.py:5: RuntimeWarning: divide by zero encountered in long_scalars\n",
      "  C = - A1[j, i] / A1[i, i]\n"
     ]
    },
    {
     "ename": "OverflowError",
     "evalue": "cannot convert float infinity to integer",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mOverflowError\u001b[0m                             Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_6060/1013505609.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      4\u001b[0m     \u001b[1;32mfor\u001b[0m \u001b[0mj\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m         \u001b[0mC\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mA1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0mA1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m         \u001b[0mb1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mb1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mC\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mb1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      7\u001b[0m         \u001b[1;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mn\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      8\u001b[0m             \u001b[0mA1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mk\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mA1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mk\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mC\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mA1\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mk\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mOverflowError\u001b[0m: cannot convert float infinity to integer"
     ]
    }
   ],
   "source": [
    "A1 = A.copy()\n",
    "b1 = b[:, 0].copy()\n",
    "for i in range(0, n+1):\n",
    "    for j in range(i + 1, n):\n",
    "        C = - A1[j, i] / A1[i, i]\n",
    "        b1[j] = b1[j] + C * b1[i]\n",
    "        for k in range(i, n):\n",
    "            A1[j, k] = A1[j, k] + C * A1[i, k]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2,  3,  5],\n",
       "       [ 0,  0, -1],\n",
       "       [ 0, -1, -5]])"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-inf,  inf,  -4.])"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Question: what are the differences of old and new version?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Your answer\n",
    "老版本的代码是在对A矩阵进行运算，即影响到了源矩阵\n",
    "而新版本的代码用copy复制了A矩阵，在一个新地址里创建了一个A1矩阵，并对A1进行运算。这样没有影响到源矩阵\n",
    "个人任务new version更优，更妥善一些。\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2: calculation x（回带求值）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(2, 5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 1, 0]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(n-1, -1, -1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.zeros(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0., 0., 0.])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\12157\\AppData\\Local\\Temp/ipykernel_6060/1157410073.py:7: RuntimeWarning: divide by zero encountered in double_scalars\n",
      "  x[i] = (b1[i] - sumX) / A1[i, i]\n"
     ]
    }
   ],
   "source": [
    "for i in range(n-1, -1, -1):\n",
    "    \n",
    "    sumX = 0\n",
    "    for k in range(i + 1, n):\n",
    "        sumX = sumX + A1[i, k] * x[k]\n",
    "        \n",
    "    x[i] = (b1[i] - sumX) / A1[i, i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-inf,  inf,  -4.])"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 3: verification（计算结果验证）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "# use python matrix library\n",
    "\n",
    "inverseA = np.linalg.inv(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ -8.,   9.,  -2.],\n",
       "       [  9., -11.,   3.],\n",
       "       [ -2.,   3.,  -1.]])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inverseA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "x2 = inverseA @ b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([10.,  5., -5.])"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# with matrix method\n",
    "x2[:, 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-inf,  inf,  -4.])"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# with hand written Guass elimination method\n",
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 4: share your experience here\n",
    "\n",
    "最大的问题就是这两个报错，希望老师有空能讲解一下\n",
    "\n",
    "IndexError: index 50 is out of bounds for axis 0 with size 50\n",
    "\n",
    "OverflowError: cannot convert float infinity to integer\n",
    "\n",
    "实在是不知道该怎么避免这两个报错 查资料也查不到"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
